package com.example.demo.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.enums.SystemEnum;
import com.example.demo.common.result.R;
import com.example.demo.entity.TravelNavigation;
import com.example.demo.entity.TravelNavigationPage;
import com.example.demo.service.TravelNavigationService;
import com.example.demo.service.impl.MyAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

import static com.example.demo.common.result.R.success;

/**
 * 旅行规划表(TravelNavigation)表控制层
 *
 * @author makejava
 * @since 2024-09-03 15:49:04
 */
@RestController
@RequestMapping("travelNavigation")
public class TravelNavigationController {
    /**
     * 服务对象
     */
    @Resource
    private TravelNavigationService travelNavigationService;


    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public R list() {
        return R.success(this.travelNavigationService.listAll());
    }


    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/page")
    public R selectAll(TravelNavigationPage travelNavigation) {

        Page<TravelNavigation> page = new Page<>(travelNavigation.getPageNum(),travelNavigation.getPageSize());
        QueryWrapper<TravelNavigation> qw = new QueryWrapper<>();
        qw.like(StringUtils.isNotBlank(travelNavigation.getScenicSpotName()),"scenic_spot_name", travelNavigation.getScenicSpotName());
        qw.eq("del_flag", "0");
        qw.orderByDesc(StringUtils.isNotBlank(travelNavigation.getOrderField()),travelNavigation.getOrderField());
        Page<TravelNavigation> page1 = this.travelNavigationService.page(page, qw);
        return R.success(page1);
    }

    /**
     * 通过主键查询单条数据
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/find/{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.travelNavigationService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param travelNavigation 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public R insert(@RequestBody TravelNavigation travelNavigation) {
        return success(this.travelNavigationService.save(travelNavigation));
    }

    /**
     * 修改数据
     *
     * @param travelNavigation 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    public R update(@RequestBody TravelNavigation travelNavigation) {
        return success(this.travelNavigationService.updateById(travelNavigation));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.travelNavigationService.removeByIds(idList));
    }




}

